home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / network / pktdrvtp.zip / PKTDRVR.ZIP / MAC.TXT < prev    next >
Text File  |  1993-10-08  |  14KB  |  363 lines

  1.  
  2.                      T H E  Medium Access Control (MAC) LAYER
  3.                      ========================================
  4.                             (C) 1993 by Oliver Rehmann
  5.                              100016.732@compuserve.com
  6.                     
  7.  
  8.  
  9. Motivation
  10. ==========
  11.  
  12. When I first came into contact with the MAC layer I was a high school
  13. student. It was a dream of mine to write the worlds best network sniffer. :-)
  14.  
  15. The project failed because of the MAC layer. There was no accurate information
  16. about this layer of the OSI reference model and as a high school student 
  17. I did not have  enough money to buy all those expensive books about networks. 
  18. Another stumbling block was that I didn't have a low level driver for my LAN 
  19. adapter (NE2000).
  20.  
  21. I know there exist hundreds of books about this subject. What I am trying
  22. to convey you is a summary of information you need when working on the
  23. MAC layer of an Ethernet. Thus the information provided in this document 
  24. is only for Ethernet !!!
  25.  
  26.  
  27. History of ETHERNET
  28. ===================
  29.  
  30. Ethernet was developed by Xerox in the seventies. The specification of 
  31. Ethernet Version 1.0 has been released 1980 by Dec, Intel and Xerox
  32. (The Blue Book Ethernet).
  33.  
  34. Two years later the same group (DIX) released version 2.0 of Ethernet.
  35. Another three years later the IEEE group specified the 802.3 paper.
  36.  
  37. Quick Reference : Ethernet (Version 1.0)
  38. ----------------------------------------
  39.  
  40. Topology                : Bus
  41. Media Access            : CSMA/CD = Carrier Sense Multiple Access with 
  42.                                     Collision Detection
  43.  
  44. Throughput              : 10 Mbit/sec.
  45.  
  46. max. distance between 
  47. two stations            : 2800m
  48.  
  49. max. stations           : 1024
  50.  
  51.  
  52. Frame format:
  53. -------------
  54.  
  55. Preamble    length      : 8 Bytes
  56. Destination address     : 6 Bytes
  57. Source      address     : 6 Bytes
  58. Type field              : 2 Bytes
  59. Data field length       : 46 - 1500 Bytes
  60. Frame Checksum          : 4 Bytes
  61.                         ------------------------
  62.                           72 - 1526 Bytes
  63.                         ========================
  64.  
  65.  
  66. The OSI Reference model
  67. =======================
  68.  
  69. When talking about networks, it is useful to refer to the OSI reference 
  70. model (OSI = Open Systems Interconnection).
  71.  
  72.  
  73. ┌────────────────────────┐
  74. │ Layer 7                │
  75. │ Application            │
  76. ├────────────────────────┤
  77. │ Layer 6                │
  78. │ Presentation           │
  79. ├────────────────────────┤
  80. │ Layer 5                │
  81. │ Session                │
  82. ├────────────────────────┤
  83. │ Layer 4                │
  84. │ Transport              │
  85. ├────────────────────────┤
  86. │ Layer 3                │
  87. │ Network                │
  88. ├────────────────────────┤ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
  89. │ Layer 2b               │
  90. │ Logical Link Control   │         D a t a  L i n k  C o n t r o l
  91. │ (LLC)                  │
  92. ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┤                  L a y e r
  93. │ Layer 2a               │
  94. │ Medium Access Control  │                  (2a + 2b)
  95. │ (MAC)                  │
  96. ├────────────────────────┤ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
  97. │ Layer 1b               │
  98. │ Physical (PHY)         │              P h y s i c a l
  99. │                        │
  100. ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┤                 L a y e r
  101. │ Layer 1a               │
  102. │ Physical Medium        │                 (1a + 1b)
  103. │ Dependent (PMD)        │
  104. └────────────────────────┘ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
  105.  
  106. What I will describe are layers 2a and 2b (MAC and LLC).
  107. Normally, if you are interfacing with your LAN adapter at packet level,
  108. layer one is invisible to you. The transceiver is on this layer.
  109.  
  110. Layer 2
  111. -------
  112. Data Link Control: Errorfree Frame Transmission between physically
  113.                    connected nodes.
  114.  
  115. On this layer the programmer has to handle incoming and outgoing packets.
  116. These packets often are called frames.
  117.  
  118. IEEE 802.3 (Ethernet) Frame
  119. ===========================
  120.  
  121. ┌──────────┬────────┬─────────┬─────────┬─────────┬─────────────────┬─────────┐
  122. │ 7 Bytes  │ 1 Byte │ 6 Bytes │ 6 Bytes │ 2 Bytes │ 46...1500 Bytes │ 4 Bytes │
  123. │ Preamble │   SFD  │ Dest.   │ Source  │ Length  │ of Data         │   FCS   │
  124. │          │        │ Address │ Address │ (Type)  │ (at least 46 B) │         │
  125. └──────────┴────────┴─────────┴─────────┴─────────┼─────────────────┼─────────┘
  126.                                                   │      LLC        │
  127. legend of frame format:
  128.  
  129.   Preamble : 7 Bytes                      => 10101010
  130.   SFD      : 1 Byte Start Frame Delemiter => 10101011
  131.   
  132.   Preamble and SFD are used for synchronisation of all receivers.
  133.   
  134.   Destination address : 6 Byte hardware address of receiver
  135.   Source      address : 6 Byte hardware address of sender 
  136.   
  137.         ─ example.
  138.           
  139.           80─00─20─7F─59─E8 => 8000207F59E8
  140.  
  141.           This is called an Ethernet hardware address. They are unique.
  142.           
  143.   Length   : If this word (2 Bytes) is smaller than 5EEh (1500+18) the frame
  144.              is a standard IEEE 802.3 frame. Length represents the number of
  145.              bytes in the Data (LLC) field.
  146.              If the length field is greater than 5EEh it is an ETHERNET frame.
  147.              The difference is that length is no longer a valid length but
  148.              it represents a type. (See table in file ETHERNET.TYP)
  149.              
  150.   Data     : 46..1500 Bytes of Data. The smallest frame on an Ethernet
  151.   (LLC)      (CSMA/CD) has to be at least 64 Bytes. The header consists of
  152.              18 Bytes so the data field must hold 46 or more Bytes.
  153.              
  154.   FCS      : Frame Check Sequence. This is a cyclic redundancy checksum
  155.   
  156.  
  157. Data representation
  158. -------------------
  159.  
  160. When receiving packets from your LAN adapter (ex. through Crynrware packet 
  161. drivers) you must know what type of CPU your computer has. This is important 
  162. for data representation.
  163.  
  164. The type (length) field in an Ethernet frame always corresponds to a Big Endian 
  165. system (ex. Motorola 68000, etc.).
  166.  
  167. Intel 80x86 CPUs are Little Endian systems so you have to swap the lo and hi
  168. byte of a word.
  169.  
  170. Ex. DOD IP = 0800h -> Swap -> 0008h (on a 80x86 PC)
  171.  
  172. Summary
  173. -------
  174.  
  175. Ethernet and IEEE 802.3 frames differ from each other by the type field.
  176.  
  177. Ethernet defines different types (see file ETHERNET.TYP). 
  178.  
  179. IEEE 802.3 uses the type field as a length field to say how many bytes
  180. the data field holds. The type of the packet is stored in the LLC header
  181. which is part of the data field.
  182.  
  183. This can be very time consuming work for a LAN adapter because it 
  184. always has to look into the LLC header to determine the packet type.
  185.  
  186. Ethernet addresses
  187. ------------------
  188.  
  189. The first three bytes of an Ethernet address identify the vendor of
  190. the LAN adapter.
  191.  
  192.    example:
  193.  
  194.      08-00-09-12-7F-05  : 08-00-09 -> Vendor is Hewlett Packard  (HP)
  195.      08-00-20-24-AB-55  : 08-00-20 -> Vendor is Sun Microsystems (SUN)
  196.  
  197. The well known vendor identifiers are listed in the file ETHERNET.VND.
  198.  
  199.  
  200. Turbo Pascal definitions
  201. ------------------------
  202.  
  203. Data structures used for MAC layer handling.
  204.  
  205. TYPE
  206.  
  207.        { 6 Byte Ethernet address }
  208.        EthernetAddr = Array[00..05] of Byte;
  209.  
  210.        { Definition of a Medium Access Control header }
  211.        MACHeader    = RECORD
  212.                         DestAddr   : EthernetAddr;
  213.                         SourceAddr : EthernetAddr;
  214.                         TypeLen    : Word;
  215.                       END;
  216.  
  217.  
  218. Turbo Pascal functions
  219. ----------------------
  220.  
  221. Functions for handling data on the MAC layer.
  222.  
  223. FUNCTION SwapWord(sWord : Word) : Word;
  224. {╔══════════════════════════════════════════════════════════════════════╗
  225.  ║ FUNCTION  SwapWord;                                                  ║
  226.  ╟─────────────────┬────────────────────────────────────────────────────╢
  227.  ║ Description   : │ Swaps the lo and hi byte of a word.                ║
  228.  ║                 │ Used for type (length) field manipulation.         ║
  229.  ╟─────────────────┼────────────────────────────────────────────────────╢
  230.  ║ Creation date :